perm filename TMP.TMP[TEX,DEK]2 blob sn#465974 filedate 1979-08-13 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{{ The procedure \\{controlseq} removes a control sequence from \\{curinput.buffer}
C00010 ENDMK
CāŠ—;
{{ The procedure \\{controlseq} removes a control sequence from \\{curinput.buffer}
assuming that the initial escape character \.{\\} has already been removed.
Then this control sequence is found or entered in the \\{hash} table,
and \\{hashentry} is set.}}
procedure controlseq; {{ gets a packed name from the input }}
var len: integer; {{ length of control sequence, saved as $(\\{len}-1)$ mod $8$ }}
    id: conseq; {{ packed control sequence }}
    unpid: array [1..maxpartlen+1] of ascii; {{ unpacked version of the control sequence }}
    c: integer; {{ ascii code for a character }}
begin
SYNON	PRINTLN;PRINT('ENTERING controlseq             ',20);  SYNOFF 
for len:=1 to maxpartlen+1 do unpid[len]:=nul; {{ initialize unpacked control sequence }}
with curinput do
	begin
	{ Get first character of control sequence };
	if { first character of sequence is a letter }
	and { next input character is a letter } then
		begin  {{ two or more letters in the control sequence }}
		repeat { Get new character of control sequence }
		until (not { next input character is a letter }) or (len=maxpartlen);
		{ Skip input up to first nonletter }
		end
	end;
pack(unpid,1,id.name); {{ pack control sequence in \\{id} }}
id.name[maxpartlen+1]:=chr(ord('0')+((len-1) mod 8));
idlookup(id); {{ find or enter \\{id} in the hash table and set \\{hashentry} }}
SYNON	PRINTLN;PRINT('EXITING controlseq              ',20);  SYNOFF 
end;

{ Get first character of control sequence } =
len:=1;
unpid[1]:=buffer[curbuf]; 
increment(curbuf) {{ to look at second character next }}
{{ Note that in, e.g., \.{\\\%} the \.{\%} should not be treated as a comment delimiter }}

{ first character of sequence is a letter } = (chartype(ord(unpid[1]))=letter)

{ next input character is a letter } = (chartype(ord(buffer[curbuf]))=letter)


{ Get new character of control sequence } =
increment(len); c:=ord(buffer[curbuf]);
lower_case(c); {{ make it easy for matching }}
unpid[len]:=chr(c);
increment(curbuf)

{ Skip input up to first nonletter } =
while { next input character is a letter } do
	begin increment(len); increment(curbuf)
	end



{{ Conversely to the \\{controlseq} procedure, \\{idname}
builds the name associated with \\{eqtb}[\\h] (possibly justified with
\.{x}'s to give the correct length modulo 8) and delimited by at least one \.{nul},
and puts it in the global variable \\{conseqid}. }}
procedure idname(h:integer);
var	{ Locals for \\{idname} }
begin
if h>=hashsize then { Set \\{conseqid} to single character naming control sequence }
else { Set \\{conseqid} to name of multicharacter control sequence }
end;

{ Locals for \\{idname} } +=
c: integer; {{ ascii code for a character }}

{ Set \\{conseqid} to single character naming control sequence } =
begin
c:=h-hashsize;
if c>127 then { Set \\{conseqid} to \.{IMPOSSIBLE} }
else if c<>0 then 
	begin conseqid[1]:=chr(c);
	conseqid[2]:=nul
	end
else	{ Set \\{conseqid} to \.{NULL} };
end

{ Set \\{conseqid} to \.{IMPOSSIBLE} } =
begin
conseqid[1]:='I';
conseqid[2]:='M';
conseqid[3]:='P';
conseqid[4]:='O';
conseqid[5]:='S';
conseqid[6]:='S';
conseqid[7]:='I';
conseqid[8]:='B';
conseqid[9]:='L';
conseqid[10]:='E';
conseqid[11]:=nul
end

{ Set \\{conseqid} to \.{NULL} } =
begin
conseqid[1]:='N';
conseqid[2]:='U';
conseqid[3]:='L';
conseqid[4]:='L';
conseqid[5]:=nul
end

{ Set \\{conseqid} to name of multicharacter control... } =
if hash[h].name[1]=nul then { Set \\{conseqid} to \.{UNDEFINED} }
else	begin
	unpack(hash[h].name,conseqid,1); {{ put known characters in \\{conseqid} }}
	if { at least \\{maxpartlen} characters in control sequence } then
		{ Add \.{x}'s for correct length and \.{nul} to delimit }
	end

{ Set \\{conseqid} to \.{UNDEFINED} } =
begin
conseqid[1]:='U';
conseqid[2]:='N';
conseqid[3]:='D';
conseqid[4]:='E';
conseqid[5]:='F';
conseqid[6]:='I';
conseqid[7]:='N';
conseqid[8]:='E';
conseqid[9]:='D';
conseqid[10]:=nul
end

{ at least \\{maxpartlen} characters in control sequence } = 
conseqid[maxpartlen]<>nul

{ Locals for \\{idname} } +=
lng: integer; {{ length of control sequence modulo 8 }}
l: integer;	{{ index of a character in \\{conseqid} }}

{ Add \.{x}'s for correct length and \.{nul} to delimit } =
begin
lng:=(ord(hash[h].name[maxpartlen+1])-ord('0')+1) mod 8;
if (lng<>maxpartlen) then
	begin
	for l:=maxpartlen+1 to (maxpartlen+1+lng) do
		 conseqid[l]:=chr(170B); {{ code for \.x }}
	conseqid[maxpartlen+1+lng+1]:=nul
	end
else conseqid[maxpartlen+1]:=nul
end


procedure show_idname; {{ obtains the name of a control sequence and prints it }}
var	l: integer; {{ index in \\{conseqid} }}
begin
idname(h); {{ put name in \\{conseqid} }}
l:= 1;
while conseqid[l]<>nul do {{ print until delimiting \.{nul} }}
	begin
	printchar(conseqid[l]);
 	increment(l);
	end;
end;